-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding lib
support to crossgen
#12
Conversation
|
||
$ZIP = "$SRC_DIR\$($Env:CRATE_NAME)-$($Env:APPVEYOR_REPO_TAG_NAME)-$($Env:TARGET).zip" | ||
|
||
Copy-Item "$SRC_DIR\target\$($Env:TARGET)\release\$PKG_NAME.exe" '.\' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On windows we might want to have this as $PKG_NAME.dll
and copy it to .\win-$target-$PKG_NAME.dll
as I think GitHub don't support folders
New-Item -Type Directory -Name $STAGE | ||
Set-Location $STAGE | ||
|
||
$ZIP = "$SRC_DIR\$($Env:CRATE_NAME)-$($Env:APPVEYOR_REPO_TAG_NAME)-$($Env:TARGET).zip" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When thinking of the distribution aspect of the lib on github, I think it would be more helpful to have the bare-ddl not zipped.
In my mind, when building a library on another language, it could be possible to instrument the build system to download all the .so
and .dll
into a folder to distribute the package with it, and having it not-zipped would make the build system much simpler.
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess the zip archive really only makes a big difference if you have a library that produces more than one artefact (which can easily be the case). Maybe it should be something that is configurable somehow?
test -f Cargo.lock || cargo generate-lockfile | ||
|
||
cross rustc --bin $PKG_NAME --target $TARGET --release -- -C lto | ||
cp target/$TARGET/release/$PKG_NAME $stage/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think cargo generates libs in the form of ${PKG_NAME}lib.so
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought it was lib${PKG_NAME}.so
unless you manually set the lib.name
field?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, you are right!
|
||
# Install test dependencies | ||
rustup component add rustfmt-preview | ||
rustup component add clippy-preview |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if we also install bindgen
and setup a build stage responsible to build the .h
headers and publish on Github?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few quick notes here:
- we would need
cbindgen
, notbindgen
here (e.g. wraprust
code to be consumed fromC
, not the other way around) - here's an example of how to do that
- in the example it stands out to me that a
cbindgen.toml
file is included. Should we generate that as well, or leave that up to the user? It looks like it might not be required. - building with
cbindgen
can either be done from the command line or from build.rs, I'm not sure which one is preferable. But we should probably pick one.
That is neat! I would be able to have some time next week to test drive this on a sample project. One thing I've considered when reading the Issue would be to provide some feedback on the |
src/cli.rs
Outdated
@@ -18,6 +18,9 @@ pub struct Cli { | |||
/// Project name. Defaults to target directory name | |||
#[structopt(short = "n", long = "name")] | |||
name: Option<String>, | |||
/// Specify if a library template should be generated | |||
#[structopt(short = "l", long = "lib")] | |||
lib: Option<bool>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe lib: bool
should work well enough. It defaults to false
, and is only set to true
if you pass --lib
to the executable. This should make it slightly easier to access in the code.
src/main.rs
Outdated
@@ -25,6 +25,7 @@ fn main() -> Result<(), ExitFailure> { | |||
|
|||
let dir = args.dir()?; | |||
let name = args.name()?; | |||
let lib = args.lib().unwrap_or(false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If args.lib()
returns a bool
, we can remove .unwrap_or(false)
from this line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I opted for this so that it's more clear in main.rs
what the default vaulue is (instead of hiding it in cli.rs
. We can of course change this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah okay, gotcha. Perhaps a better way to be explicit about the default state is to add default_value=false
to the structopt attribute. I was a bit confused why we had 3 states for a boolean value (e.g. not passed at all, passed as true, passed as false?) instead of defaulting to a "is this option enabled? yes / no"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the general idea a lot; think this would be fine to merge as-is. Commented with a few small questions / quality-of-life improvements. Hope they're alright. Thanks for doing this! π
Oh, I've just remembered that you can pass to
|
cc/ @yoshuawuyts So I changed the CLI handling to be more direct (no I think the question of how the library template files should work is not an easy one to solve. And also, maybe we can come up with a better and more modular way of storing/ generating them β aka just having a few code snippets that can be assembled into larger scripts that get generated. But that's a bit beyond what this PR was meant to be. Also: not sure why the CI fails? Any advice on that? |
lib
support to crossgenlib
support to crossgen
@spacekookie it looks like ScreenshotThis is the cargo fmt diff: |
I agree that it'd be great to figure out something for this, but agree it's best to do so somewhere separate. Perhaps we could draft an issue for this where we can discuss the options? |
@yoshuawuyts I'll try re-running Also, I just opened #13 to discuss some of these issues π |
So, this is just quickly something I threw together on the plane β looking for some feedback! The CLI now has a `--lib` flag which is taken into account when creating a template. `Template::new` still exists, but is deprecated and points to `Template::gen_bin` (just in case this shouldn't be a breaking change). Actually generating the templates I'm not 100% sure what differences might be wanted/required for bin vs lib. So I just copied the templates directory for now. Also the write block is quite ugly now. Considering that this approach generally isn't very modular, I'm wondering if it wouldn't be possible to have a folder with travis "snippets" that are then assembled according to some user config (e.g. I want android but not wasm, but it's also a binary?) Again...WIP β happy to change stuff! Cheers! Signed-off-by: Katharina Fey <[email protected]>
Signed-off-by: Katharina Fey <[email protected]>
Signed-off-by: Katharina Fey <[email protected]>
Got a build to pass on a re-run (which means travis failures are just a clippy problem) https://travis-ci.com/yoshuawuyts/crossgen/jobs/145930817, so think this is good to merge for now! β¨ |
|
Choose one: This a π feature
So, this is just quickly something I threw together on the plane β looking for
some feedback!
The CLI now has a
--lib
flag which is taken into account when creatinga template.
Template::new
still exists, but is deprecated and pointsto
Template::gen_bin
(just in case this shouldn't be a breaking change).Actually generating the templates I'm not 100% sure what differences
might be wanted/required for bin vs lib. So I just copied the templates
directory for now.
Also the write block is quite ugly now. Considering that this approach
generally isn't very modular, I'm wondering if it wouldn't be possible
to have a folder with travis "snippets" that are then assembled according
to some user config (e.g. I want android but not wasm, but it's also a binary?)
Again...WIP β happy to change stuff!
Cheers!
Checklist
Context
This PR addresses issue #11
Semver Changes
This is a non-breaking change (for now)